package com.example.game_community.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.game_community.entity.Post;
import com.example.game_community.service.SearchService;
import com.example.game_community.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    SearchService searchService;

//    获取搜索建议列表
    @GetMapping("/searchValue")
    public Result<List<Post>> getSearchList(@RequestParam("keyword") String keyword) {
       List<Post> search =  searchService.getSearchList(keyword);
       return Result.success(search);
    }

//    获取搜索结构
    @GetMapping("/results")
    public Result<Page<Post>> getSearchResults(
            @RequestParam String keyword,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize
    ){
        return Result.success(searchService.search(keyword,page,pageSize));
    }

}
